USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0013_CABECERA_FINAL]    Script Date: 11/24/2011 11:37:51 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('WASP_M0013_CABECERA_FINAL') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0013_CABECERA_FINAL]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0013_CABECERA_FINAL]    Script Date: 11/24/2011 11:37:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[WASP_M0013_CABECERA_FINAL] AS
BEGIN
    select	
    	NroCuotas,
    	cast ((PrimaBrutaCaja / 1.19) as decimal(10,4)) as PrimaNetaCaja,
    	PrimaBrutaCaja,
    	FechaEnvio,
    	cast(PrimaBrutaPeso as decimal(10,4)) as   PrimaBrutaPeso
    
    into	 dbo.cabecera_produccion_cantidad
    from 
    	dbo.cabecera_producion_prueba
    	
    
    --espacio
    
    select 
    	'H' as TipoRegistro,
    	FechaEnvio as fechaProceso,
    	count(PrimaNetaCaja)  as CantRegVentas , 
    	Cast(sum(PrimaNetaCaja) as varchar(14)) as totalPrimaNeta,
    	Cast(sum(PrimaBrutaCaja) as varchar(14))as totalPrimaBruta,
    	--Cast(sum(PrimaNetaPeso) as varchar(14)) as totalPrimaNetaPeso,
    	Cast(sum(PrimaBrutaPeso) as varchar(14))as totalPrimaBrutaPeso,
    	cast('' as char(294)) as  filler
    
    into 	dbo.cabecera_produccion_cabecera
    from  dbo.cabecera_produccion_cantidad
    GROUP BY FechaEnvio
END    
GO


